package com.linxcong.security.order;


import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @Author:linchong
 * @CreateTime:2020-07-14 10:58
 * @Description:订单
 */
@Slf4j
@RestController
@RequestMapping("/orders")
public class OrderController {

	private RestTemplate restTemplate = new RestTemplate();

	/**
	 * 获取当前用户信息：
	 *  获取整个用户对象：@AuthenticationPrincipal User user
	 *  获取用户id：@AuthenticationPrincipal(expression="#this.id") Long userId,其他同理
	 * @param info
	 * @param user
	 * @return
	 */
	@PostMapping
	public OrderInfo create(@RequestBody  OrderInfo info,@RequestHeader String username){
		log.info("username:{}",username);
		//PriceInfo price = restTemplate.getForEntity("http://localhost:9060/prices/" + info.getProductId(), PriceInfo.class).getBody();
		//log.info("price is {}",price.getPrice());
		return info;
	}

	@GetMapping("/{id}")
	public OrderInfo getInfo(@PathVariable Long id,@RequestHeader String username){
		log.info("user is {}",username);
		log.info("orderId is {}",id);
		OrderInfo orderInfo = new OrderInfo();
		orderInfo.setId(id);
		orderInfo.setProductId(5*id);
		return orderInfo;
	}
}
